package com.blb.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.dto.EmpDTO;
import com.blb.dto.PageDTO;
import com.blb.entity.Emp;
import com.blb.service.EmpService;
import com.blb.mapper.EmpMapper;
import com.blb.vo.PageAble;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
* @author 难于
* @description 针对表【emp】的数据库操作Service实现
* @createDate 2024-03-26 18:13:24
*/
@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp>
    implements EmpService{

    @Resource
    private EmpMapper empMapper;
    @Override
    public boolean addEmp(Emp emp) {
        LocalDateTime now = LocalDateTime.now();
        Date date = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
        emp.setCreateTime(date);

        return empMapper.insert(emp) > 0;
    }

    @Override
    public List<EmpDTO> listDto() {
        return empMapper.listDto();
    }

    @Override
    public List<EmpDTO> getByName(PageAble pageAble, String username, String det) {
        pageAble.setPage((pageAble.getPage()-1) * pageAble.getSize());
        return empMapper.getByName(username,det, pageAble);

    }

}




